package cn.school.test;

import cn.school.dao.StudentDao;
import cn.school.entity.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class MybatisAdd {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();

        StudentDao mapper = session.getMapper(StudentDao.class);
        System.out.println(mapper.getClass().getName());
        Student student=new Student();
        student.setSname("林超-5");

        student.setGradeid(7L);

        student.setEnterdate(new Date());

        int r=mapper.add(student);
        System.out.println("返回了："+r);
        session.commit();//
        session.close();
    }
}
